sql - syntax for inserting hstore arrays in PostgreSQL -


New in postgrad, just thinking how the syntax will be done. For example, I have the following table:

< Pre> create table test (field 1 hstore [], field 2 text [], field3 hstore) ...

To insert entities, syntax

  is the INSERT test (field 2) value ('{"abc", "def"}');  

To insert hstore, like syntax

  INSERT test (field 3) value ('' A '=> 1.0,' b '=) & Gt; 2.4 ');  

But, what do I do for the inclusion on ' field 1 '? Something gives me an error like the following:

  INSERT test (field 1) values ​​(`{'" a "=> 1.0," b "=> 2.0', ' "A" = & gt; 3.0, "b" => 4.0 '} `)  

Any fix? Thanks!

== Edit ==


Just explained it

  INSERT ('{' a = & quot; Gt; 1.0, b = & gt; 2.0 "," a => 3.0, b => 4.0 "} ')  

The answer given below also helps , But in this particular case, a string (rather than array structure) works better with my existing code.

I think it will be a very easy time with you:

Constructor syntax can also be used:

  sal_emp VALUES ('Bill', ARRAE [10000, 10000, 10000, 10000], ARRAY [ Meeting ',' noon '] [' training ',' presentation ']]; Something like this:  
  INSERT test (field 1) value (array ['' one '=> 1.0', ' B '"= & gt; 2.0' :: hstore, '" a "=> 3.0," b "=> 4.0' :: hstore]);  

On the first element of the array, only need to insert the :: hstore but there is no injury to putting them all.

I have an array of syntax specifications Because all string parsing and quote gives me a headache.

If you are the array creator and If you can not use the settings, you can ask yourself from PostgreSQL how to do this:

  => Select the array ['A' = & gt; 1.0, 'b' = & gt; 2.0 ':: hstore,' 'a' => 3.0, 'b' => 4.0 ':: hstore; array ---------- --------------------------------------- ----------- --------- "{" one "= \ gt; \ "1.0 \", \ "b \" = & gt; \ "2.0 \" "" \ "one \" = & gt; \ "3.0 \", \ "b \" = & gt; \ "4.0 \" " 

attention Give double quotes that are wrapped in individual hstores:

  "\" \ "= \" 1.0 \ ", \" b \ "= & gt; \" 2.0 \ "  

And they use backslash-escape double quotes for their internal structure, it gives us:

  INSERT test (field 1) values ​​( '{"\" A \ "= & gt; \" 1.0 \ ", \" b \ "= & gt; \" 2.0 \ "," \ "A \" = & gt; \ "3.0 \", \ "B \" = & gt; \ "4.0 \" "} ');  

I still try to use array constructor syntax, all of these nested quotes and escapes.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -