How to insert symbol in sql database - mysqli

I am trying to insert into sql database this (Age 70+) but it only entered (Age 70) without (+) my column type is varchar what is the suitable type to include numbers and symbols???

sorry for my english.
+ this is special symbol, need to use slash. If you use php, you can use function Addslashes() and stripslashes().
you can read about this on site mysql and php dot net.
I hope that i help you.

Related

PostgreSQL in list, mixing string and int

We are using PostgreSQL 11 and have a query from Redmine database. It is a query that works fine in MySQL 8 but on PostgreSQL we get an error.
SELECT fixed_version_id
FROM issues WHERE
((issues.fixed_version_id IN ('current_version','2')));
ERROR: invalid input syntax for integer: "current_version"
LINE 1: ...d FROM issues WHERE ((issues.fixed_version_id IN ('current_v...
I understand that fixed_version_id is an int and that I quering strings. However, is other SQL like MySQL 8 you can do this and it actually returns values. But in PostgreSQL we get an error. Not sure if we have it setup wrong or if this is just the way PostgreSQL works?
Any help would be most appreciated thank you.
We ran this query
SELECT fixed_version_id
FROM issues
WHERE ((issues.fixed_version_id IN ('current_version','2')));
We were expecting Not to get an error.
SQL is a tightly typed language (seems MySql does not adhere to the standard). The only correction is using the correct type - in this case integer. But you can `CAST' an integer to text and compare.
SQL Standard:
WHERE ((cast (issues.fixed_version_id as text) IN ('current_version','2')));
Postgresql extension:
WHERE ((issues.fixed_version_id::text IN ('current_version','2')));

Trim/whitespace issue when load data from Db2 source to Postgresql DB using Talend Open source

We are seeing issue in table value which are populated from DB2 (source) to Postgres (Target).
I have including here all the job details for each component.
Based on the above approach and once the data has been populated, when we run the below query in the Postgres DB.
SELECT * FROM VMRCTTA1.VMRRCUST_SUMM where cust_gssn_cd='XY03666699' ;
SELECT * FROM VMRCTTA1.VMRRCUST_SUMM where cust_cntry_cd='847' ;
There will be no records were returned however, when we run the same query with Trim as below it works.
SELECT * FROM VMRCTTA1.VMRRCUST_SUMM where trim(cust_gssn_cd)='XY03666699' ;
SELECT * FROM VMRCTTA1.VMRRCUST_SUMM where trim(cust_cntry_cd)='847' ;
Below are the ways we have tried to overcome this but no luck.
Used tmap between source and target component.
Used trim in source component under Advanced setting.
Change the datatype in Postgres DB of cust_cntry_cd from char(5) to Character varying, this will allow value without any length restriction.
Please suggest what is missing as we have this issue in almost all the table where we have character/varchar columns.
We are using TOS.
The data type is probably character(5) in DB2.
That means that the trailing spaces are part of the column and will be migrated. You have to compare with
cust_cntry_cd = '847 '
or cast the right argument to character(5):
cust_cntry_cd = CAST ('847' AS character(5))
Maybe you could delete all spaces in the advanced settings of the tDB2Input component.
Like the screen :

saving point type data to pg server

I have a function in postgres that inserts data to a table, and one of the columns is of type point.
I don't know how to save my gotten data to an acceptable form for the function to save my data.
The problematic code in question is :
CREATE OR REPLACE FUNCTION db."setMessage"(eml text, msg text, lat text, lng text)
...
INSERT INTO
db.messages
VALUES
(DEFAULT,
id,
$2,
DEFAULT,
ST_SetSRID(ST_MakePoint($3::float, $4::float), 4326)
);
The error received when i call the function is:
ERROR: function st_makepoint(double precision, double precision) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Context: PL/pgSQL function "setMessage" line 9 at SQL statement
I have tries to save the point in string format ('POINT(12.22343 64.22233)'), tried not casting the st_makepoint arguments, and inserting without the outer function (ST_SetSRID).
could anyone tell me what I'm doing wrong?
SOLUTION:
So the method of success was following this link to get the needed libraries. after that i created the required extensions, and now i have access to the desired functions.
To install PostGIS, follow the instructions for your operating system at https://postgis.net/install.
Then, to enable it on your db you can do CREATE EXTENSION postgis; from psql or PGAdmin.
I had a similar problem, that postgres didn't find the function st_makepoint even though postgis extension was installed and I used the correct types for arguments. It turned out that the search path did not contain postgis.
Solution was: alter database my_db set search_path = my_schema, public, postgis;
Hope it helps somebody.
I tried to re-install postgis extension and have tried many soluations but did not work for me.
I just edit my query and put extensions keyword before functions name like this:
INSERT INTO
db.messages
VALUES
(DEFAULT,
id,
$2,
DEFAULT,
extensions.ST_SetSRID(extensions.ST_MakePoint($3::float, $4::float), 4326)
);
That worked for me.

PostgreSQL - Query on hstore - column does not exists

I wonder if someone could have an idea what is going wrong with this simple query on a hstore column in PostgreSQL 9.2
The queries are runned in pgAdmin
select attributeValue->"CODE_MUN" from shapefile_feature
returns: « attributevalue » column does not exists
when doing:
select * from shapefile_feature;
all the columns are returned including attributeValue, the hstore column
what is the problem?
PostgreSQL distinguish between "identifiers" and 'literal'. Identifiers are schema, table, column's, .. names, literals are others. A attribute in hstore are not SQL identifiers. So you have to pass their names as literals. Operator "->" is only shortcut for function "fetchval(hstore, text)" with possibility be indexed.
select attributeValue->'CODE_MUN' from shapefile_feature
is internally transformed to (don't do this transformation by self!)
select fetchval(attributeValue, 'CODE_MUN') from shapefile_feature
on buggy example in transformed form, you can better understand to error message:
select fetchval(attributeValue, "CODE_MUN") from shapefile_feature
PostgreSQL tries to find column "CODE_MUN" in shapefile_feature, bacause used double quotes means identifiers (in case sensitive notation).

syb_describe in DBD::Sybase

I am looking to extract Sybase datatype for all the columns in a table. When I try to achieve this using $sth->{TYPE}, I get a numeric version of the datatype (i.e. instead of sybase datatype varchar, I get 0).
From the DBD::Sybase documentation, I noticed that SYBTYPE attribute of syb_describe function might be able to produce what I am looking for. But it seems that my understanding is not proper. SYBTYPE also prints datatype in numeric form only.
Is there any way to fetch the textual representation of actual Sybase datatype (instead of the number)?
It sounds like you wish to reverse engineer the create table definition. Here is an SQL script you can use for Sybase or SQL Server tables.
select c.name,
"type(size)"=case
when t.name in ("char", "varchar") then
t.name + "(" + rtrim(convert(char(3), c.length)) + ")"
else t.name
end,
"null"=case
when convert(bit, (c.status & 8)) = 0 then "NOT NULL"
else "NULL"
end
from syscolumns c, systypes t
where c.id = object_id("my_table_name")
and c.usertype *= t.usertype
order by c.colid
go
Note: This could still be edited with a nawk script to create a real SQL schema file.
The nawk script would strip the header, add "create table my_table_name", add commas, strip the footer and add a "go".
Good SQL, good night!
I found a workaround (Note: This does not answer the question though):
What I did was simply joined the sysobjects, systypes and syscolumns system tables.